package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.EventPostSO;

@Entity
@Table(name = "EVENT_POST")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class EventPost extends Post {
	
	private static final long serialVersionUID = 1L;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "EVENT_ID", nullable = false)
	private Event event;
	
	public EventPostSO convertToServiceObject(String... ignoreProperties) {
		EventPostSO so = (EventPostSO) convert(new EventPostSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"event","user"}));
		so.setUser(super.getUser().convertToServiceObject(new String[]{"socialUsers"}));
		so.setEvent(event.convertToServiceObject(new String[]{"moderators", "posts"}));
		return so;
	}
	
	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	@Override
	public String toString() {
		return "EventPost [event=" + event + "]";
	}
	
	

}
